//
//  YWSingleton.h
//  maintain
//
//  Created by 郑想 on 15/10/30.
//  Copyright © 2015年 ewin. All rights reserved.
//
#import <Foundation/Foundation.h>

#define YWSingletonH(name) +(instancetype)share##name;

#if __has_feature(objc_arc)

#define YWSingletonM(name)                         \
    static id _instace;                            \
                                                   \
    +(id)allocWithZone : (struct _NSZone*)zone     \
    {                                              \
        static dispatch_once_t onceToken;          \
        dispatch_once(&onceToken, ^{               \
            _instace = [super allocWithZone:zone]; \
        });                                        \
        return _instace;                           \
    }                                              \
                                                   \
    +(instancetype)share##name                     \
    {                                              \
        static dispatch_once_t onceToken;          \
        dispatch_once(&onceToken, ^{               \
            _instace = [[self alloc] init];        \
        });                                        \
        return _instace;                           \
    }                                              \
                                                   \
    -(id)copyWithZone : (NSZone*)zone              \
    {                                              \
        return _instace;                           \
    }
//如果是非ARC
#else

#define HMSingletonM(name)                                \
    static id _instace;                                   \
                                                          \
    +(id)allocWithZone : (struct _NSZone*)zone            \
    {                                                     \
        static dispatch_once_t onceToken;                 \
        dispatch_once(&onceToken, ^{                      \
            _instace = [super allocWithZone:zone];        \
        });                                               \
        return _instace;                                  \
    }                                                     \
                                                          \
    +(instancetype)share##name                            \
    {                                                     \
        static dispatch_once_t onceToken;                 \
        dispatch_once(&onceToken, ^{                      \
            _instace = [[self alloc] init];               \
        });                                               \
        return _instace;                                  \
    }                                                     \
                                                          \
    -(id)copyWithZone : (NSZone*)zone                     \
    {                                                     \
        return _instace;                                  \
    }                                                     \
                                                          \
    -(oneway void)release{} - (id)retain { return self; } \
    -(NSUInteger)retainCount { return 1; }                \
    -(id)autorelease { return self; }

#endif
